<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>S110_nRF51822/Source/ble/ble_uuid_util.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="alias.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="alias.js"></script>

<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>


<script type="text/javascript">
  jQuery(document).ready(function () {
    if(gref){ // Number all _img and _table classes
      gref();
    }
  });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nRF51822 BLE SDK
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('ble__uuid__util_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">S110_nRF51822/Source/ble/ble_uuid_util.c</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.</span>
<a name="l00002"></a>00002 <span class="comment"> *</span>
<a name="l00003"></a>00003 <span class="comment"> * The information contained herein is property of Nordic Semiconductor ASA.</span>
<a name="l00004"></a>00004 <span class="comment"> * Terms and conditions of usage are described in detail in NORDIC</span>
<a name="l00005"></a>00005 <span class="comment"> * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Licensees are granted free, non-transferable use of the information. NO</span>
<a name="l00008"></a>00008 <span class="comment"> * WARRANTY of ANY KIND is provided. This heading must NOT be removed from</span>
<a name="l00009"></a>00009 <span class="comment"> * the file.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * $LastChangedRevision$</span>
<a name="l00012"></a>00012 <span class="comment"> */</span>
<a name="l00013"></a>00013  
<a name="l00014"></a>00014 <span class="preprocessor">#include &quot;<a class="code" href="ble__uuid__util_8h.html">ble_uuid_util.h</a>&quot;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &quot;nrf_error.h&quot;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &quot;ble_types.h&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="ble__sdk__util_8h.html">ble_sdk_util.h</a>&quot;</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 
<a name="l00022"></a>00022 <span class="preprocessor">#define BASE_UUID128_DEFAULT_COUNT (sizeof(s_base_uuid128_default) / sizeof(ble_uuid128_t))</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span>
<a name="l00025"></a>00025 <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="structble__uuid128__t.html" title="128 bit UUID values.">ble_uuid128_t</a> s_base_uuid128_default[] =
<a name="l00026"></a>00026 {
<a name="l00027"></a>00027     {
<a name="l00028"></a>00028         {
<a name="l00029"></a>00029             0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
<a name="l00030"></a>00030             0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
<a name="l00031"></a>00031         }
<a name="l00032"></a>00032     }
<a name="l00033"></a>00033 };
<a name="l00034"></a>00034 
<a name="l00035"></a>00035 
<a name="l00036"></a>00036 <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="structble__uuid128__t.html" title="128 bit UUID values.">ble_uuid128_t</a> * <span class="keyword">volatile</span> sp_base_uuid128      = s_base_uuid128_default;       
<a name="l00037"></a>00037 <span class="keyword">static</span> <span class="keyword">volatile</span> uint8_t               s_base_uuid128_count = BASE_UUID128_DEFAULT_COUNT;   
<a name="l00040"></a><a class="code" href="group__ble__sdk__lib__uuid.html#ga5d4dd4f63e0bbe18837f9dfab4c0c15d">00040</a> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__lib__uuid.html#ga5d4dd4f63e0bbe18837f9dfab4c0c15d" title="Initialise the UUID module 128-bit base list.">ble_uuid_set_base</a>(uint16_t base_uuid128_count, <span class="keyword">const</span> <a class="code" href="structble__uuid128__t.html" title="128 bit UUID values.">ble_uuid128_t</a> * p_base_uuid128)
<a name="l00041"></a>00041 {
<a name="l00042"></a>00042     sp_base_uuid128      = p_base_uuid128;
<a name="l00043"></a>00043     s_base_uuid128_count = base_uuid128_count;
<a name="l00044"></a>00044 }
<a name="l00045"></a>00045 
<a name="l00046"></a>00046 
<a name="l00047"></a><a class="code" href="group__ble__sdk__lib__uuid.html#ga882bee030ada24a6ade6521b62f42131">00047</a> uint32_t <a class="code" href="group__ble__sdk__lib__uuid.html#ga882bee030ada24a6ade6521b62f42131" title="Decode the UUID bytes (16-bit or 128-bit) in Little-Endian to uuid_t structure.">ble_uuid_decode</a>(uint8_t uuid_len, <span class="keyword">const</span> uint8_t * p_encoded, <a class="code" href="structble__uuid__t.html" title="Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs.">ble_uuid_t</a> * p_uuid)
<a name="l00048"></a>00048 {
<a name="l00049"></a>00049     p_uuid-&gt;<a class="code" href="structble__uuid__t.html#a1d127017fb298b889f4ba24752d08b8e">type</a> = <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#ga0dfc5e26324c8cd7226f3941acbf5b7e">BLE_UUID_TYPE_UNKNOWN</a>;
<a name="l00050"></a>00050     p_uuid-&gt;<a class="code" href="structble__uuid__t.html#aaa1ded1f77a9c12a196ed4ba2ce5f95d">uuid</a> = 0x0000;
<a name="l00051"></a>00051 
<a name="l00052"></a>00052     <span class="keywordflow">if</span> (uuid_len == <span class="keyword">sizeof</span>(<a class="code" href="group__ble__sdk__lib__util.html#gaa6f104ea023a4a6a56ef05f30b0cfdc3" title="type for holding an encoded (i.e. little endian) 16 bit unsigned integer.">uint16_le_t</a>))
<a name="l00053"></a>00053     {
<a name="l00054"></a>00054         p_uuid-&gt;<a class="code" href="structble__uuid__t.html#a1d127017fb298b889f4ba24752d08b8e">type</a> = <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#gae549d14b15783ba52dae5fdd5f9ac959">BLE_UUID_TYPE_BLE</a>;
<a name="l00055"></a>00055         p_uuid-&gt;<a class="code" href="structble__uuid__t.html#aaa1ded1f77a9c12a196ed4ba2ce5f95d">uuid</a> = <a class="code" href="group__ble__sdk__lib__util.html#gaf30655fd762a9debe0b499db3a9451f7" title="Inline function for decoding a uint16 value.">uint16_decode</a>(p_encoded);
<a name="l00056"></a>00056         
<a name="l00057"></a>00057         <span class="keywordflow">if</span> (p_uuid-&gt;<a class="code" href="structble__uuid__t.html#aaa1ded1f77a9c12a196ed4ba2ce5f95d">uuid</a> != 0x0000)
<a name="l00058"></a>00058         {
<a name="l00059"></a>00059             <span class="keywordflow">return</span> <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>;
<a name="l00060"></a>00060         }
<a name="l00061"></a>00061     }
<a name="l00062"></a>00062     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (uuid_len == <span class="keyword">sizeof</span>(<a class="code" href="structble__uuid128__t.html" title="128 bit UUID values.">ble_uuid128_t</a>))
<a name="l00063"></a>00063     {
<a name="l00064"></a>00064         uint8_t i;
<a name="l00065"></a>00065 
<a name="l00066"></a>00066         p_uuid-&gt;<a class="code" href="structble__uuid__t.html#aaa1ded1f77a9c12a196ed4ba2ce5f95d">uuid</a> = <a class="code" href="group__ble__sdk__lib__util.html#gaf30655fd762a9debe0b499db3a9451f7" title="Inline function for decoding a uint16 value.">uint16_decode</a>(&amp;p_encoded[12]);
<a name="l00067"></a>00067         
<a name="l00068"></a>00068         <span class="comment">// Determine the type</span>
<a name="l00069"></a>00069         i = s_base_uuid128_count;
<a name="l00070"></a>00070         <span class="keywordflow">while</span> (i--)
<a name="l00071"></a>00071         {
<a name="l00072"></a>00072             <span class="keywordflow">if</span> (
<a name="l00073"></a>00073                 (memcmp((<span class="keywordtype">void</span> *)&amp;p_encoded[0], &amp;sp_base_uuid128[i].uuid128[0], 12) == 0)
<a name="l00074"></a>00074                 &amp;&amp;
<a name="l00075"></a>00075                 (p_encoded[14] == sp_base_uuid128[i].uuid128[14])
<a name="l00076"></a>00076                 &amp;&amp;
<a name="l00077"></a>00077                 (p_encoded[15] == sp_base_uuid128[i].uuid128[15])
<a name="l00078"></a>00078             )
<a name="l00079"></a>00079             {
<a name="l00080"></a>00080                 <span class="comment">// Table indexed from 1 by caller, hence increment by 1</span>
<a name="l00081"></a>00081                 p_uuid-&gt;<a class="code" href="structble__uuid__t.html#a1d127017fb298b889f4ba24752d08b8e">type</a> = i + 1;
<a name="l00082"></a>00082                 <span class="keywordflow">return</span> <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>;
<a name="l00083"></a>00083             }
<a name="l00084"></a>00084         }
<a name="l00085"></a>00085     }
<a name="l00086"></a>00086     
<a name="l00087"></a>00087     <span class="keywordflow">return</span> <a class="code" href="group__nrf__error.html#gaca6d57e218563351e7abdbdebb049f69" title="Invalid Data.">NRF_ERROR_INVALID_DATA</a>;
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089 
<a name="l00090"></a>00090 
<a name="l00091"></a><a class="code" href="group__ble__sdk__lib__uuid.html#ga8af3492a4ce7d3db30915dbcbd8e83b9">00091</a> uint32_t <a class="code" href="group__ble__sdk__lib__uuid.html#ga8af3492a4ce7d3db30915dbcbd8e83b9" title="Encode the uuid_t structure into Little-Endian UUID bytes (16-bit or 128-bit).">ble_uuid_encode</a>(<span class="keyword">const</span> <a class="code" href="structble__uuid__t.html" title="Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs.">ble_uuid_t</a> * p_uuid, uint8_t * p_uuid_len, uint8_t * p_encoded)
<a name="l00092"></a>00092 {
<a name="l00093"></a>00093     *p_uuid_len = 0;
<a name="l00094"></a>00094 
<a name="l00095"></a>00095     <span class="keywordflow">if</span> (p_uuid-&gt;<a class="code" href="structble__uuid__t.html#a1d127017fb298b889f4ba24752d08b8e">type</a> == <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#gae549d14b15783ba52dae5fdd5f9ac959">BLE_UUID_TYPE_BLE</a>)
<a name="l00096"></a>00096     {
<a name="l00097"></a>00097         <span class="keywordflow">if</span> (p_encoded != NULL)
<a name="l00098"></a>00098         {
<a name="l00099"></a>00099             (void)<a class="code" href="group__ble__sdk__lib__util.html#gab58c28346b89382397aa7a716bf9a178" title="Inline function for encoding a uint16 value.">uint16_encode</a>(p_uuid-&gt;<a class="code" href="structble__uuid__t.html#aaa1ded1f77a9c12a196ed4ba2ce5f95d">uuid</a>, p_encoded);
<a name="l00100"></a>00100         }
<a name="l00101"></a>00101         *p_uuid_len = <span class="keyword">sizeof</span>(<a class="code" href="group__ble__sdk__lib__util.html#gaa6f104ea023a4a6a56ef05f30b0cfdc3" title="type for holding an encoded (i.e. little endian) 16 bit unsigned integer.">uint16_le_t</a>);
<a name="l00102"></a>00102         <span class="keywordflow">return</span> <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>;
<a name="l00103"></a>00103     }
<a name="l00104"></a>00104     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (
<a name="l00105"></a>00105         (p_uuid-&gt;<a class="code" href="structble__uuid__t.html#a1d127017fb298b889f4ba24752d08b8e">type</a> &gt;= <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#ga7bdcaea9ea91ab20be755d78833da46d">BLE_UUID_TYPE_VENDOR_BEGIN</a>)
<a name="l00106"></a>00106         &amp;&amp;
<a name="l00107"></a>00107         (p_uuid-&gt;<a class="code" href="structble__uuid__t.html#a1d127017fb298b889f4ba24752d08b8e">type</a> &lt;= s_base_uuid128_count)
<a name="l00108"></a>00108     )
<a name="l00109"></a>00109     {
<a name="l00110"></a>00110         <span class="keywordflow">if</span> (p_encoded != NULL)
<a name="l00111"></a>00111         {
<a name="l00112"></a>00112             memcpy(p_encoded,
<a name="l00113"></a>00113                    &amp;(sp_base_uuid128[p_uuid-&gt;<a class="code" href="structble__uuid__t.html#a1d127017fb298b889f4ba24752d08b8e">type</a> - 1].uuid128[0]),
<a name="l00114"></a>00114                    <span class="keyword">sizeof</span>(<a class="code" href="structble__uuid128__t.html" title="128 bit UUID values.">ble_uuid128_t</a>));
<a name="l00115"></a>00115             (void)<a class="code" href="group__ble__sdk__lib__util.html#gab58c28346b89382397aa7a716bf9a178" title="Inline function for encoding a uint16 value.">uint16_encode</a>(p_uuid-&gt;<a class="code" href="structble__uuid__t.html#aaa1ded1f77a9c12a196ed4ba2ce5f95d">uuid</a>, &amp;p_encoded[12]);
<a name="l00116"></a>00116         }
<a name="l00117"></a>00117         *p_uuid_len = <span class="keyword">sizeof</span>(<a class="code" href="structble__uuid128__t.html" title="128 bit UUID values.">ble_uuid128_t</a>);
<a name="l00118"></a>00118         <span class="keywordflow">return</span> <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>;
<a name="l00119"></a>00119     }
<a name="l00120"></a>00120 
<a name="l00121"></a>00121     <span class="keywordflow">return</span> <a class="code" href="group__nrf__error.html#ga0a5831cf5092e0dd43a01869676ee076" title="Invalid Parameter.">NRF_ERROR_INVALID_PARAM</a>;
<a name="l00122"></a>00122 }
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>ble_uuid_util.c</b>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
      Copyright &copy 2006-2011 <a href="http://www.nordicsemi.no" style="text-decoration:none">Nordic Semiconductor</a>.
      All Rights Reserved.
      <a href="disclaimer.html">Disclaimer</a>
    </li>
   </ul>
 </div>


</body>
</html>
